<?php
/**
 * универсальный вывод
 *
 */
class View_UniversalInference{
	/**
	 * вывод на главной
	 */
	public static function getIndex($arrUniversalInference, $showEssenceName = true){
  	$str = '';
		$str .= '<div class="bottom_border">';
			if (!empty($arrUniversalInference)){
			  $str .= self::getTable($arrUniversalInference, $showEssenceName);
			}
			else $str .= '<h3>Выберите раздел</h3>';
		$str .=  '</div>';
		return $str;
	}
	
	/**
	 * вывод на других страница(не на главной)
	 */
	public static function getCommon($arrUniversalInference, $showEssenceName = true){
  	$str = '';
		$str .= '<div class="bottom_border">';
			if (!empty($arrUniversalInference)){
			  $str .= self::getTable($arrUniversalInference, $showEssenceName);
			}
		$str .=  '</div>';
		echo $str;
	}

	/**
	 * вывод таблицы на индексной
	 */
	public static function getTable($arrUniversalInference, $showEssenceName){
	  	$str = '<table cellspacing="0" width="100%">';
				foreach ($arrUniversalInference as $key=>$essence){
		  		$str .= '<tr class="main">';
		  			$str .= '<td class="open"><a id="open_' . $essence['type'] . '_' . $essence['ID_' . $essence['type']] . '" href="javascript:index.getFullInfo(\'' . $essence['type'] . '\', ' . $essence['ID_' . $essence['type']] . ');"><img src="' . W_IMAGES . 'background/index_open_info.png"/></a></td>';
		  			$str .= '<td class="essenceType">';
							switch ($essence['type']){
								case 'article': $str .= '<img src="' . W_IMAGES . 'background/min_article.png" title="Статья"/>'; break;
								case 'question': $str .= '<img src="' . W_IMAGES . 'background/min_question.png" title="Вопрос"/>'; break;
								case 'tutorial_lesson': $str .= '<img src="' . W_IMAGES . 'background/min_lesson.png" title="Урок"/>'; break;
								case 'solution': $str .= '<img src="' . W_IMAGES . 'background/min_solution.png" title="Готовое решение"/>'; break;
								case 'community': $str .= '<img src="' . W_IMAGES . 'background/min_community.png" title="Сообщество"/>'; break;
								case 'crequest': $str .= '<img src="' . W_IMAGES . 'link/link_crequest.png" title="Заявки на контент"/>'; break;
							}
						$str .= '</td>';
		  			$str .= '<td class="crumb">';
							switch ($essence['type']){
								case 'article': $str .= View_UniversalInference::getArticle($essence, $showEssenceName); break;
								case 'question': $str .= View_UniversalInference::getQuestion($essence, $showEssenceName); break;
								case 'tutorial_lesson': $str .= View_UniversalInference::getLesson($essence, $showEssenceName); break;
								case 'solution': $str .= View_UniversalInference::getSolution($essence, $showEssenceName); break;
								case 'community': $str .= View_UniversalInference::getCommunity($essence, $showEssenceName); break;
								case 'crequest': $str .= View_UniversalInference::getCrequest($essence, $showEssenceName);; break;
							}
						$str .= '</td>';


		  			$str .= '<td class="dateImg"><img src="' . W_IMAGES . 'background/bg_date.gif" title="Дата"></td>';
		  			$str .= '<td class="date"><p>' . Service_Date::getCaseDateForUser($essence['creation']) . '</p></td>';

		  			$str .= '<td class="userImg"><img src="' . W_IMAGES . 'background/bg_user.gif"/></td>';
		  			$str .= '<td class="user"><p class="fade"><a class="underGreen" href="' . W_ABSPATH . 'user/' . $essence['login'] . '">' . $essence['login'] . '</a><i class="fade2"></i></p></td>';

		  			$str .= '<td class="ratingImg"><img src="' . W_IMAGES . 'background/bg_rating_one.jpg"/></td>';
		  			$str .= '<td class="rating"><p>' . (($essence['type'] == 'community') ? '&ndash;' : round($essence['total_mark'], 2)) . '</p></td>';

		  			$str .= '<td class="commentsImg"><img src="' . W_IMAGES . 'background/index_commens.png"/></td>';
		  			$str .= '<td class="comments"><p><a class="none" href="' . W_ABSPATH . Service_Essence::getEssenceUrl(Service_Essence::getEssenceTypeIDByName($essence['type']), $essence['ID_' . $essence['type']]) . '#comments">' . ($essence['type'] == 'question' ? $essence['comment_amount'] + $essence['answer_amount'] : $essence['comment_amount']) .'</a></p></td>';

		  		$str .= '<tr>';
		  			$str .= '<td colspan="11" class="fullInfo" id="' . $essence['type'] . '_' . $essence['ID_' . $essence['type']] . '">';
		  			$str .= '</td>';
		  		$str .= '</tr>';

		  		$str .= '<tr class="bottom">';
		  			$str .= '<td class="border" colspan="11"></td>';
		  		$str .= '</tr>';
				}
	  	$str .= '</table>';
	  	return $str;
	}

  /**
   * отображение простого списка статей, для универсального вывода
   */
  public static function getArticle($arr, $showEssenceName){
  	$str = '';
		$str .=  '<ul class="crumbs">';
			if ($showEssenceName) $str .=  '<li><b>Статья</b></li>';
			if (!empty($arr['ID_root_folder'])) $str .=  '<li><a href="' . W_ABSPATH . 'articles?idFolder=' . $arr['ID_root_folder'] . '">' . $arr['root_folder_name'] . '</a></li>';
			$str .=  '<li>';
				$str .=  View_Article::getArticleEssence($arr);
			$str .=  '</li>';
			$str .=  '<li class="last">' . ($arr['essence_type'] == 14 ? '<b>' : '') . '<a href="' . W_ABSPATH . 'article/' . $arr['ID_article'] . '/">' . $arr['name'] . '</a>' . ($arr['essence_type'] == 14 ? '</b>' : NULL) . '</li>';
		$str .=  '</ul>';
		return $str;
	}

  /**
   * отображение простого списка сообществ, для универсального вывода
   */
  public static function getCommunity($arr, $showEssenceName){
  $str = '';
      $str .=  '<ul class="crumbs">';
          if ($showEssenceName) $str .=  '<li><b>Сообщество</b></li>';
          if (!empty($arr['ID_root_folder'])) $str .=  '<li><a href="' . W_ABSPATH . 'articles?idFolder=' . $arr['ID_root_folder'] . '">' . $arr['root_folder_name'] . '</a></li>';
          $str .=  '<li class="last"><a href="' . W_ABSPATH . 'community/' . $arr['ID_community'] . '/">' . $arr['name'] . '</a></li>';
      $str .=  '</ul>';
      return $str;
  }

    public static function getCrequest($arr, $showEssenceName){
      $str = '';
		$str .=  '<ul class="crumbs">';
			if ($showEssenceName) $str .=  '<li><b>Заявка на контент</b></li>';
			$str .=  '<li><a href="' . W_ABSPATH . Service_Essence::getEssenceTypeRootUrlByID($arr['essence_type']) . '" title="Перейти к разделу">' . Service_Essence::getEssenceTypeHumanName($arr['essence_type'] ) . '</a></li>';
			$str .=  '<li><a href="' . W_ABSPATH . 'articles?idFolder=' . $arr['ID_folder'] . '">' . $arr['folder_name'] . '</a></li>';
			$str .=  '<li class="last"><a href="' . W_ABSPATH . 'crequest/' . $arr['ID_crequest'] . '/">' . $arr['name'] . '</a></li>';
		$str .=  '</ul>';
		return $str;
    }
    

  /**
   * отображение простого списка вопросов, для универсального вывода
   */
  public static function getQuestion($arr, $showEssenceName){
  	$str = '';
		$str .=  '<ul class="crumbs">';
			if ($showEssenceName) $str .=  '<li><b>Вопрос</b></li>';
			$str .=  ($arr['show_folder'] == 0 ? '<li><a href="' . W_ABSPATH . 'questions?folder=' . $arr['ID_root_folder'] . '&pageNum=1">' . $arr['root_folder_name'] . '</a></li>' : NULL);
			$str .=  '<li><a href="' . W_ABSPATH . 'questions?folder=' . $arr['ID_folder'] . '&pageNum=1">' . $arr['folderName'] . ' </a></li>';
			$str .=  '<li class="last"><a href="' . W_ABSPATH . 'question/' . $arr['ID_question'] . '">' . $arr['name'] . '</a></li>';
			$str .=  '';
		$str .=  '</ul>';
		return $str;
	}

  /**
   * отображение простого списка готовых решений, для универсального вывода
   */
  public static function getSolution($arr, $showEssenceName){
  	$str = '';
		$str .=  '<ul class="crumbs">';
			if ($showEssenceName) $str .=  '<li><b>Готовое решение</b></li>';
			if (!empty($arr['ID_root_folder']) AND !empty($arr['ID_root_root_folder'])) $str .=  '<li><a href="' . W_ABSPATH . 'solutions?idFolder=' . $arr['ID_root_folder'] . '&pageNum=1">' . $arr['root_folder_name'] . '</a></li>';
			$str .=  '<li><a href="' . W_ABSPATH . 'solutions?idFolder=' . $arr['ID_folder'] . '&pageNum=1">' . $arr['folder_name'] . '</a></li>';
			$str .=  '<li class="last"><a href="' . W_ABSPATH . 'solution/' . $arr['ID_solution'] . '/">' . $arr['solution_name'] . '</a></li>';
		$str .=  '</ul>';
		return $str;
	}

  /**
   * отображение простого списка уроков, для универсального вывода
   */
  public static function getLesson($arr, $showEssenceName){
  	$str = '';
			$str .=  '<ul class="crumbs">';
			if ($showEssenceName) $str .=  '<li><b>Урок</b></li>';
			if (!empty($arr['ID_root_folder']) AND !empty($arr['ID_root_root_folder'])) $str .=  '<li><a href="' . W_ABSPATH . 'articles?idFolder=' . $arr['ID_root_folder'] . '">' . $arr['root_folder_name'] . '</a></li>';
			$str .=  '<li><a href="' . W_ABSPATH . 'tutorial/' . $arr['url_name'] . '">' . $arr['tutorial_name'] . '</a></li>';
			$str .=  '<li><a href="' . W_ABSPATH . 'tutorial/' . $arr['url_name'] . '/theme/' . $arr['ID_tutorial_theme'] . '/1">' . $arr['theme_name'] . '</a></li>';
			$str .=  '<li class="last"><a href="' . W_ABSPATH . 'tutorial/' . $arr['url_name'] . '/lesson/' . $arr['ID_tutorial_lesson'] . '">' . $arr['lesson_name'] . '</a></li>';
			$str .=  '</ul>';
		return $str;
	}

	/**
	 * получаем доп информацию по статье
	 *
	 */
	public static function getArticleInfo($arr){
		$str = $arr['annotation'];
		$str .= self::getTags($arr['tags'], 1);
		return $str;
	}

	/**
	 * получаем доп информацию по сообществу
	 *
	 */
	public static function getCommunityInfo($arr){
		$str = '<div class="statsIndex">';
			$str .= '<ul>';
				$str .= '<li class="kol_prosmotr">Количество просмотров: <strong>' . $arr['browsing_amount'] . '</strong></li>';
				$str .= '<li class="prosmotrelo"> Посмотрело: <strong>' . $arr['visitors'] . '</strong></li>';
				$str .= '<li class="comentaruev">Комментариев: <strong>' . $arr['comment_amount'] . '</strong></li>';
			$str .= '</ul>';
		$str .= '</div>';
		return $str;
	}

	/**
	 * получаем доп информацию по Уроку
	 *
	 */
	public static function getLessonInfo($arr){
		$str = '<div class="article_text wysiwyg-content">';
		$str .= $arr['lesson'];
		$str .= '</div>';
		$str .= self::getTags($arr['tags'], 7);
		return $str;
	}

	/**
	 * получаем доп информацию по готовому решению
	 *
	 */
	public static function getSolutionInfo($arr){
		$str = '';
		$str .= $arr['concise_description'];
		if ($arr['file_size']) $str .= '<p>Размер файла: <b>' . $arr['file_size'] . ' байт</b></p>';
		$str .= self::getTags($arr['tags'], 10);
		return $str;
	}

	/**
	 * получаем доп информацию по вопросу
	 *
	 */
	public static function getQuestionInfo($arr){
		$str = '';
		if (!is_NULL($arr['ID_best_answer'])) {
       $classNameStatus = 'time_ok';
       $classTitle = 'Ответ найден';
       $str .= '<span class="ostalos_' . $classNameStatus . '" title="' . $classTitle . '">' . $classTitle . '</span>';
     }
     else {
       $expireTime = $arr['answer_time'] != 5 ? Service_Date::getQuestionExpireTimeLeft($arr['creation'], $arr['answer_time']) : '<span class="inf_symbol">&#8734</span>';
       $expireStatus = $arr['answer_time'] != 5 ? Service_Date::getQuestionExpireStatus($arr['creation'], $arr['answer_time']) : 3;
       switch ($expireStatus) {
         case 0: $classNameStatus = 'time_red'; $classTitle = 'Время истекло';break;
         case 1: $classNameStatus = 'time_pred'; $classTitle = 'Время скоро истекает'; break;
         default: case 2: $classNameStatus = 'time'; $classTitle = 'Время ещё есть';break;
         case 3: $classNameStatus = 'time_inf'; $classTitle = 'Ограничения по времени отсутствуют'; break;
       }
       $str .= '<span class="ostalos_' . $classNameStatus . '" title="' . $classTitle . '">' . (($expireTime === false) ? 'Время истекло' : ($arr['answer_time'] != 5 ? 'осталось: ' . $expireTime : 'без ограничений')) . '</span>';
     }
		 $str .= $arr['text'];
		 $str .= self::getTags($arr['tags'], 5);
		return $str;
	}

    /**
     * получаем доп инфу по заявкам
     */
    public static function getCrequestInfo($arr){
		 $str = $arr['text'];
      return $str;
    }

	/**
	 * вывод тегов
	 */
	public static function getTags($atrTags, $type){
		return '<div class="tags">' . View_Tags::showTagsInList($atrTags, $type, 'all_tags') . '</div>';
	}

	/**
	 * вывод фильтрции потока
	 *
	 */
	public static function showFilter($arrUserIndexVars){
		if ($arrUserIndexVars['indexFilterSize'] == 0){
			foreach ($arrUserIndexVars as $key=>$val)
				$arrUserIndexVarsNew[$key] = 1;
			$arrUserIndexVarsNew['indexFilterSize'] = 15;
			$arrUserIndexVars = $arrUserIndexVarsNew;
		}
		echo '<div class="rounded_box">';
			echo '<div class="rounded_box_bottom">';
  			echo '<div class="rounded_box_right">';
	  			echo '<div class="rounded_box_left">';
		  			echo '<div class="rounded_box_right_top">';
			  			echo '<div class="rounded_box_right_bootom">';
				  			echo '<div class="rounded_box_left_bottom">';
					  			echo '<div class="rounded_box_left_top"  id="universalInferenceFilter">';

					  				echo '<h3>Выберите нужные разделы</h3>';

					  				echo '<div class="filterEssences">';
					  					echo '<div class="filterEssencesLeft">';
						  					echo '<div class="filterEssencesRight">';
						  						echo '<p class="filter_essence_article">';
						  							echo '<a href="' . W_ABSPATH . 'articles"><span>Статьи</span></a>';
						  							echo '<a class="filterJS" href="javascript:index.filterEssence(\'article\', ' . ($arrUserIndexVars['indexFilterArticle'] == 1 ? 0 : 1) . ');"><img src="' . W_IMAGES . 'background/index_filter_tab_' . ($arrUserIndexVars['indexFilterArticle'] ? 'plus' : 'minus') . '.png" /></a>';
						  						echo '</p>';
						  						echo '</div>';
							  			echo '</div>';
						  			echo '</div>';

					  				echo '<div class="filterEssences">';
					  					echo '<div class="filterEssencesLeft">';
						  					echo '<div class="filterEssencesRight">';
						  						echo '<p class="filter_essence_question">';
						  							echo '<a href="' . W_ABSPATH . 'questions"><span>Вопросы и ответы</span></a>';
						  							echo '<a class="filterJS" href="javascript:index.filterEssence(\'question\', ' . ($arrUserIndexVars['indexFilterQuestion'] == 0 ? 1 : 0) . ');"><img src="' . W_IMAGES . 'background/index_filter_tab_' . ($arrUserIndexVars['indexFilterQuestion'] ? 'plus' : 'minus') . '.png" /></a>';
						  						echo '</p>';
								  			echo '</div>';
							  			echo '</div>';
						  			echo '</div>';

					  				echo '<div class="filterEssences">';
					  					echo '<div class="filterEssencesLeft">';
						  					echo '<div class="filterEssencesRight">';
						  						echo '<p class="filter_essence_solution">';
						  							echo '<a href="' . W_ABSPATH . 'solutions"><span>Готовые решения</span></a>';
						  							echo '<a class="filterJS" href="javascript:index.filterEssence(\'solution\', ' . ($arrUserIndexVars['indexFilterSolution'] == 0 ? 1 : 0) . ');"><img src="' . W_IMAGES . 'background/index_filter_tab_' . ($arrUserIndexVars['indexFilterSolution'] ? 'plus' : 'minus') . '.png" /></a>';
						  						echo '</p>';
						  						echo '</div>';
							  			echo '</div>';
						  			echo '</div>';

					  				echo '<div class="filterEssences">';
					  					echo '<div class="filterEssencesLeft">';
						  					echo '<div class="filterEssencesRight">';
						  						echo '<p class="filter_essence_tutorialLesson">';
						  							echo '<a href="' . W_ABSPATH . 'tutorials"><span>Самоучитель</span></a>';
						  							echo '<a class="filterJS" href="javascript:index.filterEssence(\'tutorialLesson\', ' . ($arrUserIndexVars['indexFilterTutorialLesson'] == 0 ? 1 : 0) . ');"><img src="' . W_IMAGES . 'background/index_filter_tab_' . ($arrUserIndexVars['indexFilterTutorialLesson'] ? 'plus' : 'minus') . '.png" /></a>';
						  						echo '</p>';
						  						echo '</div>';
							  			echo '</div>';
						  			echo '</div>';

					  				echo '<div class="filterEssences">';
					  					echo '<div class="filterEssencesLeft">';
						  					echo '<div class="filterEssencesRight">';
						  						echo '<p class="filter_essence_community">';
						  							echo '<a href="' . W_ABSPATH . 'communities"><span>Сообщества</span></a>';
						  							echo '<a class="filterJS" href="javascript:index.filterEssence(\'community\', ' . ($arrUserIndexVars['indexFilterCommunity'] == 0 ? 1 : 0) . ');"><img src="' . W_IMAGES . 'background/index_filter_tab_' . ($arrUserIndexVars['indexFilterCommunity'] ? 'plus' : 'minus') . '.png" /></a>';
						  						echo '</p>';
						  						echo '</div>';
							  			echo '</div>';
						  			echo '</div>';

					  				echo '<div class="filterEssences">';
					  					echo '<div class="filterEssencesLeft">';
						  					echo '<div class="filterEssencesRight">';
						  						echo '<p class="filter_essence_crequest">';
						  							echo '<a href="' . W_ABSPATH . 'crequest"><span>Заявки на контент</span></a>';
						  							echo '<a class="filterJS" href="javascript:index.filterEssence(\'crequest\', ' . ($arrUserIndexVars['indexFilterCrequest'] == 0 ? 1 : 0) . ');"><img src="' . W_IMAGES . 'background/index_filter_tab_' . ($arrUserIndexVars['indexFilterCrequest'] ? 'plus' : 'minus') . '.png" /></a>';
						  						echo '</p>';
						  						echo '</div>';
							  			echo '</div>';
						  			echo '</div>';

						  			echo '<p class="filterCount">Количество</p>';
					  			echo '<form>';
					  				echo '<input type="hidden" id="articleIndexFiler" name="articleIndexFiler" value="' . ($arrUserIndexVars['indexFilterArticle']) . '"/>';
					  				echo '<input type="hidden" id="questionIndexFiler" name="questionIndexFiler" value="' . ($arrUserIndexVars['indexFilterQuestion']) . '"/>';
					  				echo '<input type="hidden" id="solutionIndexFiler" name="solutionIndexFiler" value="' . ($arrUserIndexVars['indexFilterSolution']) . '"/>';
					  				echo '<input type="hidden" id="tutorialLessonIndexFiler" name="tutorialLessonIndexFiler" value="' . ($arrUserIndexVars['indexFilterTutorialLesson']) . '"/>';
					  				echo '<input type="hidden" id="communityIndexFiler" name="communityIndexFiler" value="' . ($arrUserIndexVars['indexFilterCommunity']) . '"/>';
					  				echo '<input type="hidden" id="crequestIndexFiler" name="crequestIndexFiler" value="' . ($arrUserIndexVars['indexFilterCrequest']) . '"/>';
					  				echo '<input type="hidden" id="sizeIndexFiler" name="sizeIndexFiler" value="' . ($arrUserIndexVars['indexFilterSize'] == 0 ? 15 : $arrUserIndexVars['indexFilterSize']) . '"/>';
					  			echo '</form>';
						  			?>
						  			<script type="text/javascript">
											trackbar.getObject('two').init({
												onMove : function() {
													if(this.firstIndex == 1){
														$("#sizeIndexFiler").val(this.leftValue);
														$('#universalInferenceFilter').stopTime('timerIndex');
														$('#universalInferenceFilter').oneTime(200, 'timerIndex', function(){index.update();});
													}
													else this.firstIndex = 1;
												},
												dual : false, // two intervals
												width : 175, // px
												leftLimit : 10, // unit of value
												leftValue : <?php echo ($arrUserIndexVars['indexFilterSize'])?>, // unit of value
												rightLimit : 50, // unit of value
												rightValue : 50, // unit of value
												roundUp : 5,
												hehe : ":-)"
											});
										</script>
										<?

					  			echo '</div>';
				  			echo '</div>';
			  			echo '</div>';
		  			echo '</div>';
	  			echo '</div>';
  			echo '</div>';
			echo '</div>';
		echo '</div>';
	}
}
?>